
clear 
set scheme lean2, permanent
global pm = char(177) 
set more off

gl date = c(current_date)
if c(os) == "MacOSX" gl user "/Users/`c(username)'"
else if c(os) == "Windows" gl user "C:\Users\\`c(username)'"
else if c(os) == "Unix" gl user "/usr/`c(username)'"
di "$user

set graphics on

global path_data_processed "\data\processed"
global path_output "\data\output"

 
clear all
set more off

cd "$path_data_processed"
use "robustnessexperiment3.dta", clear

cd "$path_output"
 
drop if t15med==1

gen cons=1

gen anyinfo_noprior=anyinfo*noprior

gen prior_high_conf=(prior_conf>3)
gen anyinfo_prior_high_conf=anyinfo*prior_high_conf

qui sum prior_conf
gen z_prior_conf=((prior_conf-r(mean))/r(sd))
gen z_posterior_conf=((posterior_conf-r(mean))/r(sd)) // note: also standardize posterior confidence by mean and SD of prior confidence to make this meaningful.

gen D_z_conf=z_posterior_conf-z_prior_conf

gen shock=signal-prior // this is the general shock variable.
replace shock=0 if control_prior==1|control_noprior==1|tanchor==1

gen shock_prior_high_conf=shock*prior_high_conf
gen prior_prior_high_conf=prior*prior_high_conf

gen shock_t15avg=shock*t15avg
gen shock_t30=shock*t30

gen shock_placebo=shock if t5==1|control_prior==1 // this is the shock variable for the placebo analysis.
replace shock_placebo=5-prior if tanchor==1
gen shock_placebo_tanchor=shock_placebo*tanchor

global controls female atleast_bachelor age agesq log_inc midwest south west inc_NR

loc experiments "updating updating updating updating posterior"

preserve

clear all
eststo clear
estimates drop _all

set obs 10
qui gen x = 1
qui gen y = 1

loc columns = 0

foreach choice in `experiments' {
    loc ++columns
    qui eststo col`columns': reg x y
}

restore
loc colnum = 1
loc colnames ""


    reg updating shock t5 t15avg t30 tanchor prior z_prior_conf $controls cons, r nocons, if t5==1|t15avg==1|t30==1|tanchor==1|control_prior==1
    sigstar shock, prec(3)
    estadd loc thisstat2 = "`r(bstar)'": col1
    estadd loc thisstat3 = "`r(sestar)'": col1
	sigstar prior, prec(3)
    estadd loc thisstat26 = "`r(bstar)'": col1
    estadd loc thisstat27 = "`r(sestar)'": col1
	qui sum updating if t5==1|t15avg==1|t30==1|tanchor==1|control_prior==1
    estadd loc thisstat29 = r(N): col1
	estadd loc thisstat31 = "T5,T15": col1
	estadd loc thisstat32 = "T30,TA,C": col1

	reg updating shock shock_prior_high_conf prior_high_conf z_prior_conf prior t5 t15avg t30 tanchor prior_prior_high_conf $controls cons, r nocons, if t15avg==1|t30==1|t5==1|control_prior==1|tanchor==1
    sigstar shock, prec(3)
    estadd loc thisstat2 = "`r(bstar)'": col2
    estadd loc thisstat3 = "`r(sestar)'": col2
	sigstar shock_prior_high_conf, prec(3)
    estadd loc thisstat5 = "`r(bstar)'": col2
    estadd loc thisstat6 = "`r(sestar)'": col2
	sigstar prior, prec(3)
    estadd loc thisstat26 = "`r(bstar)'": col2
    estadd loc thisstat27 = "`r(sestar)'": col2
	qui sum updating if t5==1|t15avg==1|t30==1|tanchor==1|control_prior==1
    estadd loc thisstat29 = r(N): col2
	estadd loc thisstat31 = "T5,T15,": col2
	estadd loc thisstat32 = "T30,TA,C": col2

	reg updating shock shock_t15avg shock_t30 t5 t15avg t30 tanchor prior z_prior_conf $controls cons, r nocons, if t5==1|t15avg==1|t30==1|tanchor==1|control_prior==1
    sigstar shock, prec(3)
    estadd loc thisstat2 = "`r(bstar)'": col3
    estadd loc thisstat3 = "`r(sestar)'": col3
	sigstar shock_t15avg, prec(3)
    estadd loc thisstat8 = "`r(bstar)'": col3
    estadd loc thisstat9 = "`r(sestar)'": col3
	sigstar shock_t30, prec(3)
    estadd loc thisstat11 = "`r(bstar)'": col3
    estadd loc thisstat12 = "`r(sestar)'": col3
	sigstar prior, prec(3)
    estadd loc thisstat26 = "`r(bstar)'": col3
    estadd loc thisstat27 = "`r(sestar)'": col3
	qui sum updating if t5==1|t15avg==1|t30==1|tanchor==1|control_prior==1
    estadd loc thisstat29 = r(N): col3
	estadd loc thisstat31 = "T5,T15,": col3
	estadd loc thisstat32 = "T30,TA,C": col3
	
	reg updating shock_placebo shock_placebo_tanchor t5 tanchor prior z_prior_conf $controls cons, r nocons, if t5==1|tanchor==1|control_prior==1
    sigstar shock_placebo, prec(3)
    estadd loc thisstat2 = "`r(bstar)'": col4
    estadd loc thisstat3 = "`r(sestar)'": col4
	sigstar shock_placebo_tanchor, prec(3)
    estadd loc thisstat14 = "`r(bstar)'": col4
    estadd loc thisstat15 = "`r(sestar)'": col4
	sigstar prior, prec(3)
    estadd loc thisstat26 = "`r(bstar)'": col4
    estadd loc thisstat27 = "`r(sestar)'": col4
	qui sum updating if t5==1|tanchor==1|control_prior==1
    estadd loc thisstat29 = r(N): col4
	estadd loc thisstat31 = "T5,": col4
	estadd loc thisstat32 = "TA,C": col4
	
	reg posterior anyinfo anyinfo_noprior noprior $controls cons, r nocons, if t5==1|t5noprior==1|control_prior==1|control_noprior==1
    sigstar anyinfo, prec(3)
    estadd loc thisstat17 = "`r(bstar)'": col5
    estadd loc thisstat18 = "`r(sestar)'": col5
	sigstar anyinfo_noprior, prec(3)
    estadd loc thisstat20 = "`r(bstar)'": col5
    estadd loc thisstat21 = "`r(sestar)'": col5
	sigstar noprior, prec(3)
    estadd loc thisstat23 = "`r(bstar)'": col5
    estadd loc thisstat24 = "`r(sestar)'": col5
	qui sum posterior if t5==1|t5noprior==1|control_prior==1|control_noprior==1
    estadd loc thisstat29 = r(N): col5
	estadd loc thisstat31 = "T5,T5b,": col5
	estadd loc thisstat32 = "C,Cb": col5
	
	loc ++colnum
    loc colnames "`colnames' `"`: var la `choice''"'"

loc rowlabels " " " "Shock" " " " " "Shock $\times$" "Confident" " " "Shock $\times$" "T15" " " "Shock $\times$" "T30" " " "Shock $\times$" "TAnchor" " " "Signal 5\%" " " " " "Signal 5\% $\times$" "No prior" " " "No prior" " " " " "Prior" " " " " "Observations" " " "Sample" " " " "   "
loc rowstats ""

forval i = 1/32 {
    loc rowstats "`rowstats' thisstat`i'"
}

esttab * using "learningrate_RRpilot.tex", replace cells(none) booktabs nonotes nomtitles /*nonum*/ compress alignment(c) nogap noobs nobaselevels label stats(`rowstats', labels(`rowlabels')) ///
      mgroups("Updating" "Posterior" , pattern(1 0 0 0 1 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))

eststo clear	







